
//
//  CollectionViewExtension.swift
//  HuaDaoPeifu
//
//  Created by Erickson on 16/4/1.
//  Copyright © 2016年 paiyipai. All rights reserved.
//


import UIKit

extension UICollectionView {
    func pyp_IndexPathsForElementsInRect(_ rect:CGRect) -> [IndexPath]? {
        let allLayoutAttributes = self.collectionViewLayout.layoutAttributesForElements(in: rect)
        
        if allLayoutAttributes?.count == 0 {
            return nil
        }
        var indexPaths = [IndexPath]()
        for layoutAttributes in allLayoutAttributes! {
            let indexPath = layoutAttributes.indexPath
            indexPaths.append(indexPath)
        }
        return indexPaths
        
    }
}
